<?php

namespace app\common\model\search;


trait PhoneRecordSearch
{

    public function searchStartDateAttr($query, $value, $data)
    {
        if (!empty($value)) {
            return $query->where([['call_time', ">=", $value." 00:00:00"]]);
        }
        return $query;
    }

    public function searchEndDateAttr($query, $value, $data)
    {
        if (!empty($value)) {
            return $query->where([['call_time', "<=", $value." 23:59:59"]]);
        }
        return $query;
    }

    public function searchStatusAttr($query, $value, $data)
    {
        if ($value !== "") {
            return $query->where('status', (int)$value);
        }
        return $query;
    }

    public function getHomeOfCallAttr($value, $data)
    {
        if (!empty($value)) {
            $value["full_text"] = $value["province"] . $value["city"];
            $value["is_local"] = $value["area_code"] === "0431";
        }
        return $value;
    }

    public function getStatusTextAttr($value, $data): string
    {
        return $data["status"] === 0 ? "未处理" : "已处理";
    }


}
